import axios from 'axios';

export const BaseUrl = 'http://localhost:8081';

// 登录接口
export const login = async (data) => {
    try {
        const response = await axios.post(BaseUrl + '/v1/users/api/login', data);
        return response.data;
    } catch (err) {
        console.log(err);
    }
};

// 上传文件接口
export const uploadFile = async (params) => {
    try {
        const response = await axios.post(
            BaseUrl + '/v1/notes/api/uploadNote',
            params,
            { headers: { 'Content-Type': 'multipart/form-data' } } // 告诉服务器我这是文件
        );
        return response.data;
    } catch (err) {
        console.log(err);
    }
};

// 获取今日笔记文件列表
export const getTodayNoteFilesList = async (userId, fileFilter) => {
    try {
        const response = await axios.get(BaseUrl + '/v1/notes/api/getTodayNoteFilesList', {
            params: {
                userId,
                fileFilter,
            },
        });
        return response.data;
    } catch (err) {
        console.log(err);
    }
};

// 获取以往笔记文件列表
export const getEarlyNoteFilesList = async (userId, fileFilter, pageNum) => {
    // console.log(userId, fileFilter, pageNum);
    try {
        const response = await axios.get(BaseUrl + '/v1/notes/api/getEarlyNoteFilesList', {
            params: {
                userId,
                fileFilter,
                pageNum,
            },
        });
        return response.data;
    } catch (err) {
        console.log(err);
    }
};

// 获取今日上传笔记记录
export const getTodayNoteRecordsList = async (userId) => {
    try {
        const response = await axios.get(BaseUrl + '/v1/notes/api/getTodayNoteRecords', {
            params: {
                userId,
            },
        });
        console.log(response);
        return response.data;
    } catch (err) {
        console.log(err);
    }
};

// 获取以往笔记记录
export const getEarlyNoteRecordsList = async (userId, pageNum) => {
    try {
        const response = await axios.get(BaseUrl + '/v1/notes/api/getEarlyNoteRecords', {
            params: {
                userId,
                pageNum,
            },
        });
        // console.log(response);
        return response.data;
    } catch (err) {
        console.log(err);
    }
};

// 删除某条笔记记录
export const deleteNoteRecord = async (noteId) => {
    try {
        const response = await axios.post(BaseUrl + '/v1/notes/api/deleteNote/' + noteId);
        console.log(response);
        return response.data;
    } catch (err) {
        console.log(err);
    }
};

// 获取好友列表
export const getFriendsList = async (userId) => {
    try {
        const response = await axios.get(BaseUrl + '/v1/chat/api/getFriendList', {
            params: {
                userId,
            },
        });
        return response.data;
    } catch (err) {
        console.log(err);
    }
};
